Ext.define('app.customer.archive.grid', {
	extend : "Ext.grid.Panel",
	alias : 'widget.customerGridWidget',
	frame : false,
	border : false,
	requires : [ 'app.customer.model.customer', 'app.customer.archive.form' ],
	initComponent : function() {
		var me = this;
		var me = this;
		var columns = me.createColumns();
		var store = me.createStore();
		var dockitems = new Array();
		var queryarry = me.createQuery(store);
		if (queryarry != null) {
			me.qf = widget.search(queryarry);
			dockitems.push(me.qf);
		}
		var toolarray = me.createTool();
		if (toolarray.length > 0) {
			dockitems.push(widget.toolbar(toolarray));
		}
		dockitems.push(widget.paging(store));
		Ext.apply(me, {
			store : store,
			columns : columns,
			singleExpand : me.singleExpand || true,
			dockedItems : dockitems
		});
		store.load();
		me.callParent(arguments);
	},
	createTool : function() {
		var me = this;
		var array = new Array();
		utils.pushbtnarray(array, {
			text : '新增',
			handler : function() {
				Ext.create('app.customer.archive.form', {
					urlType : me.pannelParam.urlType,
					parentTarget : me
				}).show();
			}
		});
		utils.pushbtnarray(array, {
			text : '修改',
			handler : function() {
				var rec = utils.single(me);
				if (rec != null) {
					Ext.create('app.customer.archive.form', {
						urlType : me.pannelParam.urlType,
						parentTarget : me,
						customerId : rec.get('customerId')
					}).show();
				} else {
					Ext.Msg.alert('提示', '请选择记录');
				}
			}
		});
		utils.pushbtnarray(array, {
			text : '删除',
			handler : function() {
				var rec = utils.single(me);
				if (rec != null) {
					var param = {
						customerId : rec.get('customerId')
					};
					evt.confirm(me, '是否删除?', systemUrl + '/boyon/customer/'
							+ me.pannelParam.urlType + '/delete', param,
							function() {
								me.store.reload();
							});
				} else {
					Ext.Msg.alert('提示', '请选择记录');
				}
			}
		});
		utils.pushbtnarray(array, {
			text : '重置密码',
			handler : function() {
				var rec = utils.single(me);
				if (rec != null) {
					var param = {
						customerId : rec.get('customerId')
					};
					evt.confirm(me, '是否重置密码?', systemUrl + '/boyon/customer/'
							+ me.pannelParam.urlType + '/reset/pass', param,
							function() {
								me.store.reload();
							});
				} else {
					Ext.Msg.alert('提示', '请选择记录');
				}
			}
		});
		return array;
	},
	createQuery : function(store) {
		var me = this;
		var param = {};
		var array = new Array();
		array.push(widget.queryConfig({
			xtype : 'textfield',
			name : 'customerNo',
			fieldLabel : '客户编号:'
		}));
		array.push(widget.queryConfig({
			xtype : 'textfield',
			name : 'customerName',
			fieldLabel : '客户名称:'
		}));
		array.push(widget.queryConfig({
			xtype : 'valueWidget',
			name : 'customerType',
			fieldLabel : '客户类型:',
			valueField : 'value',
			editable : false,
			displayField : 'displayName',
			valueType : 11
		}));
		param['bl'] = 'center';
		param['items'] = array;
		param['ds'] = store;
		var array = new Array();
		param['btn'] = array;
		return param;
	},
	createStore : function() {
		var me = this;
		return widget.ds({
			clazz : 'app.customer.model.customer',
			url : systemUrl + '/boyon/customer/' + me.pannelParam.urlType
					+ '/query'
		});
	},
	createColumns : function() {
		var array = new Array();
		array.push(widget.column({
			dataIndex : 'customerId',
			width : 80,
			text : '客户ID'
		}));
		array.push(widget.column({
			dataIndex : 'customerNo',
			width : 80,
			text : '编号'
		}));
		array.push(widget.column({
			dataIndex : 'customerType',
			text : '客户类型',
			width : 80,
			renderer : function(v) {
				return utils.getValueField('t' + 11, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'customerName',
			width : 120,
			text : '客户名称'
		}));
		array.push(widget.column({
			dataIndex : 'customerShort',
			width : 120,
			text : '简称'
		}));
		array.push(widget.column({
			dataIndex : 'linkMan',
			width : 120,
			text : '联系人'
		}));
		array.push(widget.column({
			dataIndex : 'phone',
			width : 120,
			text : '电话'
		}));
		array.push(widget.column({
			dataIndex : 'address',
			width : 120,
			text : '地址'
		}));
		array.push(widget.column({
			dataIndex : 'regionCode',
			width : 120,
			text : '所在区域'
		}));
		array.push(widget.column({
			dataIndex : 'www',
			width : 120,
			text : '网站'
		}));
		array.push(widget.column({
			dataIndex : 'fax',
			width : 120,
			text : '传真'
		}));
		array.push(widget.column({
			dataIndex : 'postcode',
			width : 120,
			text : '邮政编码'
		}));
		array.push(widget.column({
			dataIndex : 'creditPrice',
			width : 120,
			text : '信用额度'
		}));
		array.push(widget.column({
			dataIndex : 'payType',
			width : 120,
			text : '支付类型',
			renderer : function(v) {
				return utils.getValueField('t' + 12, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'settlementType',
			width : 120,
			text : '结算方式',
			renderer : function(v) {
				return utils.getValueField('t' + 13, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'invoiceType',
			width : 120,
			text : '开票类型',
			renderer : function(v) {
				return utils.getValueField('t' + 14, v);
			}
		}));
		array.push(widget.column({
			dataIndex : 'bankName',
			width : 120,
			text : '开户行'
		}));
		array.push(widget.column({
			dataIndex : 'accountName',
			width : 120,
			text : '户头'
		}));
		array.push(widget.column({
			dataIndex : 'account',
			width : 120,
			text : '开户账号'
		}));
		return array;
	},
	reloadStore : function() {
		var me = this;
		me.store.reload();
	},
	getRecordData : function() {
		var me = this;
		var rec = utils.single(me);
		return rec;
	}
});